﻿using System.Collections.Generic;
using Models;
using Views;

namespace Presenters
{
    /// <summary>
    /// Presenter for the Add Databases window
    /// </summary>
    public class AddDatabasesPresenter : PresenterBase<IAddDatabasesView>
    {
        /// <summary>
        /// Initialise the AddDatabases presenter
        /// </summary>
        /// <param name="view">An instance that impliments IAddDatabasesView</param>
        /// <param name="parentQueryTabView">A reference to the Query Tab view that launched the Add Databases process</param>
        public AddDatabasesPresenter(IAddDatabasesView view, IQueryView parentQueryTabView)
            : base(view)
        {
            m_ParentQueryTabView = parentQueryTabView;

            View.SetupWizard(m_ParentQueryTabView.DatabaseList);
        }

        /// <summary>
        /// Add the supplied list of databases to the list of databases in the query tab that launched the add databases process
        /// </summary>
        /// <param name="selectedDatabases">The list of databases to add to the query tab's database list</param>
        public void UpdateQueryTabDatabaseList(List<Models.Database> selectedDatabases)
        {
            if (selectedDatabases != null)
            {
                List<Models.Database> currentDatabases = m_ParentQueryTabView.DatabaseList ?? new List<Database>();
                currentDatabases.AddRange(selectedDatabases);
                m_ParentQueryTabView.DatabaseList = currentDatabases;
            }
        }

        /// <summary>
        /// The Query Tab view that we were lauched from
        /// </summary>
        private IQueryView m_ParentQueryTabView;
    }
}
